;(function(){

	var table = new Table('#roleTable',{
		url: '/admin/api/role',
		toolbar: "#roleTableBTNs", //工具列
		modal:"#saveRole",
		uniqueId: 'id',
		columns: [
			{field:'ck',checkbox:true},
			{field:'groupName',title:'角色名'},
			{field:'remark',title:'备注'},
			{field:'createTime',title:'创建时间'},
			{field:'updateTime',title:'更新时间'},
		]
	})
		.add()
	    .del()
		.upd();

	//ADD_RIGHT
	function handleRoleAddRight(){
		var row=table.selected();
		if(row){
			Utils.showRemote({url:"/admin/api/role/"+row.id+"/modal_authority.html"},function ($modal) {
				$('input:checkbox',$modal).uniform();
				$('.sure',$modal).on('click',function(){
					var authorities = [];
					$('input[type="checkbox"]:checked',$modal).each(function (i) {
							 authorities.push($(this).val());
					})
					$.ajax({
						url: '/admin/api/role/'+row.id+'/right',
						type: 'PUT',
						data: {rightIds:authorities},
						success: function(respEntity){
							if(respEntity.content == true){
								Utils.alert('操作提醒','操作成功!');
							}
						},
					});
				});
			})
		}else Utils.alert('警告','请选择一行记录!');
	}
	$('#roleTableBTNs button.addRoleRight').on('click',function(){handleRoleAddRight();});	//add roleRight
})();